package br.com.promotora10.bens.banco;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import br.com.promotora10.bens.validacoes.ValidaCodigoPfPj;

//@ManagedBean (name="bancoBeans")
//@SessionScoped
public class BancoBeans implements Serializable {
	Banco banco = new Banco();
	ValidaCodigoPfPj valida = new ValidaCodigoPfPj();
	BancoCrud crud = new BancoCrud();
	public Banco getBanco() {
		return banco;
	}
	public void setBanco(Banco banco) {
		this.banco = banco;
	}
	public ValidaCodigoPfPj getValida() {
		return valida;
	}
	public void setValida(ValidaCodigoPfPj valida) {
		this.valida = valida;
	}
	public BancoCrud getCrud() {
		return crud;
	}
	public void setCrud(BancoCrud crud) {
		this.crud = crud;
	}
	
	public void limpar(){
		banco = new Banco();
	}
	public void salvar(){
		FacesContext context = FacesContext.getCurrentInstance(); 
		if (valida.validaCodigoCliente(banco.getCnpj())){
			System.out.println("Banco salvo. \n " + banco.getCnpj());
 
	        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Banco cadastrado com sucesso!",""));
	        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,null, banco.getCodigo() + " - " + banco.getNome() + "\n" + banco.getEmail()));
	        limpar();
		} else {
	        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Erro(s) encontrado(s)!\n",""));
	        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,banco.getCnpj().toUpperCase(), " inválido!"));
			System.out.println("Dados imcompletos!!!");
		}
	}
	
}
